<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title>修改</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="/static/admin/public/css/bootstrap.min.css?v=3.4.0" rel="stylesheet">
    <link href="/static/admin/public/css/font-awesome.min.css?v=4.3.0" rel="stylesheet">
    <link href="/static/admin/public/css/animate.min.css" rel="stylesheet">
    <link href="/static/toastr/toastr.min.css" rel="stylesheet"></link>

<!--    <link href="/static/admin/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css?v=3.2.0" rel="stylesheet">-->
    <link href="/static/admin/public/css/style.min.css?v=3.2.0" rel="stylesheet">
    <link href="/static/admin/plugins/iCheck/custom.css?v=3.2.0" rel="stylesheet">
</head>
<body class="fixed-sidebar full-height-layout gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins" >
        <div class="ibox-title">
            <h5>修改</h5>
            <div class="pull-right">
                <a href="javascript:window.history.back()" class="btn btn-link">返回</a>
            </div>
        </div>
        <div class="ibox-content">
            <form id="commentForm" class="form-horizontal m-t">
                <div class="form-group"><label class="col-sm-2 control-label">登录账号：</label>
                    <div class="col-sm-10"><input v-model="adminList.name" name="name" minlength="2" type="text" required="required" class="form-control"></div>
                </div>
                <div class="form-group"><label class="col-sm-2 control-label">角色名称：</label>
                    <div class="col-sm-10"><input v-model="adminList.roleName" name="roleName" minlength="2" type="text" required="required" class="form-control"></div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">权限设置：</label>

                    <div class="col-sm-10">
                        <label style="margin-right: 25px" v-for="item in ruleList" class="checkbox-inline i-checks">
                            <input style="margin-top: 2px" type="checkbox"  v-model="item.select" @click="selectRule(!item.select,item)" value="option1">{{item.name}}</label>
<!--                            <label class="checkbox-inline i-checks">-->
<!--                                <input type="checkbox" value="option2">b</label>-->
<!--                            <label class="checkbox-inline i-checks">-->
<!--                                <input type="checkbox" value="option3">c</label>-->
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-3"><button type="button" @click="updateAdmin()"  class="btn btn-primary">提交</button></div>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- 全局js -->
<script src="/static/admin/public/js/jquery-2.1.1.min.js"></script>
<script src="/static/admin/public/js/bootstrap.min.js?v=3.4.0"></script>
<script src="/static/admin/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="/static/admin/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="/static/admin/plugins/iCheck/js/icheck.min.js"></script>
<script src="/static/admin/plugins/layer/layer.min.js"></script>
<script type="text/javascript" src="/static/vue/vue.js"></script>
<!-- 自定义js -->
<script type="text/javascript" src="/static/util/axios.min.js"></script>
<script type="text/javascript" src="/static/admin/api/require.js"></script>
<script type="text/javascript" src="/static/admin/api/publicAjax.js"></script>

<!-- 第三方插件 -->

<script src="/static/toastr/toastr.min.js"></script>
<script src="/static/toastr/customToastr.js"></script>

<script src="/static/admin/plugins/validate/jquery.validate.min.js"></script>
<script src="/static/admin/plugins/validate/messages_zh.min.js"></script>


<!--编译器-->
<!-- 配置文件 -->
<script type="text/javascript" src="/static/admin/plugins/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/static/admin/plugins/ueditor/ueditor.all.js"></script>
<script>
    var id = "{$id}";
    var vmAddChannel = new Vue({
        el:"#commentForm",
        data:{
            id:id,
            adminList:{},
            ruleList:[],
            selectItem:true,
            selectRuleList:[]
        },
        methods:{
            getDetail:function (id) {
                var el = this;
                var postData = {
                    "id":el.id
                }
                AjaxPost(postData,'/admin/admin/getAdminById').then((response)=>{
                    console.log(response)
                    if(response.result){
                        el.adminList = response.result
                        el.getRuleList(response.result)
                        if(response.result.rule){
                            el.selectRuleList = response.result.rule.split(',')
                        }
                    }
                }).catch(()=>{
                    // window.location.href='/admin/trade/index'
                })
            },
            getRuleList:function(item){
                var el = this
                var item = item
                AjaxPostFree('/admin/admin/getRuleList').then((response)=>{
                    if(response.result){
                        $.each(response.result,(v,k)=>{
                            if(item.rule){
                                if(item.rule.split(',').indexOf(k.id.toString())>-1){
                                    k.select = true
                                }else {
                                    k.select = false
                                }
                            }else{
                                k.select = false
                            }

                        })
                        el.ruleList = response.result
                    }
                    console.log(el.ruleList)
                })
            },
            selectRule:function (isSelect,item) {
                var el = this;
                if(el.selectRuleList.indexOf(item.id.toString())>-1){
                    el.selectRuleList.splice(el.selectRuleList.indexOf(item.id.toString()),1)
                }else{
                    el.selectRuleList.push(item.id.toString())
                }
            },
            updateAdmin:function () {
                var el = this;
                var postData = {
                    "id":el.id,
                    'name':el.adminList.name,
                    'roleName':el.adminList.roleName,
                    'rule':el.selectRuleList.toString()
                }
                if($("#commentForm").valid()){
                    AjaxPost(postData,'/admin/admin/updateAdminByWhere').then((response)=>{
                        if(response.status==1){
                            $.customToastr('success',response.message)
                            setTimeout(()=>{
                                window.location.href = '/admin/admin/index'
                            },1000)
                        }
                    }).catch(()=>{
                        setTimeout(()=>{
                            window.location.href = '/admin/admin/index'
                        },1000)
                    })
                }

            }
        },
        mounted(){
            this.$nextTick(function () {
                this.getDetail()
                // this.getRuleList()
            })
        }
    })
</script>

</body>

</html>